import json
import os
from typing import Dict, Any
from server.report.config.config import Config

class SceneManager:
    def __init__(self, scene_name):
        self.config = Config()

        self.scene_dir = os.path.join(self.config.scene_dir, scene_name) 

        self.template = self._load_template()
        self.prompts = self._load_prompts()
    
    def _load_template(self) -> dict[str, Any]:
        config_path = os.path.join(self.scene_dir, "template.json")
        with open(config_path, 'r', encoding='utf-8') as f:
            return json.load(f)
    
    def _load_prompts(self) -> dict[str, Any]:
        prompts_path = os.path.join(self.scene_dir, "prompts.json")
        with open(prompts_path, 'r', encoding='utf-8') as f:
            return json.load(f)
    
    def get_section(self, section_id: str) -> Dict[str, Any]:
        for section in self.template["template_sections"]:
            if section["section_id"] == section_id:
                return section
        return None
    
    def get_prompt(self, prompt_key: str) -> dict[str, Any]:
        return self.prompts["prompts"].get(prompt_key)